# encoding: utf-8
from flask import Flask
from flask import request
from flask import make_response
import json
import re###### server

import webbrowser
import PIL.ImageGrab
import time;
import requests###### graph take and trans

###### graph take and trans############



def images():
    url = 'http://10.131.185.130:8000'
    files = {'file':('test.jpg',open('./1.jpg','rb'),'image/jpg')}
    print(files)
    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'
    }
    # r = requests.post(url, files=multiple_files, headers=headers)
    r = requests.post(url, files=files, headers=headers)
    print(r.text.split(',')[0])
    return (r.text.split(',')[0])

###### graph take and trans############

###### server ############

def loads_jsonp(_jsonp):
      try:
          return json.loads(re.match(".*?({.*}).*",_jsonp,re.S).group(1))
      except:
          print('s')
          
app = Flask(__name__)
@app.route('/', methods = ['GET','POST'])
def username():
    time.sleep(2)
    im=PIL.ImageGrab.grab()
    im.save("1.jpg",'jpeg')
    a =request.data
    print(a)
    r=images()
    resp1 = make_response(r)
    resp1.mimetype = 'text/plain'
    resp1.headers['Access-Control-Allow-Origin'] = '*'
    return resp1
#json.dumps({"great":'hello world',"skt":'bad'})

if __name__ == '__main__':
    #app.run(debug=True)
    app.run(host='127.0.0.1', port=8000)
    ###### server ############
